package com.gitee.mp.infra.utils;

import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ReflectUtil;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.function.Consumer;

/**
 * @author hongda.li
 */
public final class MilvusCommonUtils {
    private MilvusCommonUtils() {
    }

    public static <A extends Annotation> void processField(Class<?> clazz, Class<A> annotation, Consumer<Field> consumer) {
        Field[] fields = ReflectUtil.getFields(clazz, field -> AnnotationUtil.hasAnnotation(field, annotation));
        if (ArrayUtil.isEmpty(fields)) {
            return;
        }
        Arrays.stream(fields).forEach(consumer);
    }
}
